package com.sf.fy.uav.applet.pricing;

import com.sf.fy.uav.common.request.common.IdRequest;
import com.sf.fy.uav.common.request.pricing.PricingAddRequest;
import com.sf.fy.uav.common.request.pricing.PricingEditRequest;
import com.sf.fy.uav.common.request.pricing.SysPricingRequest;
import com.sf.fy.uav.common.request.user.UserExtraRequest;
import com.sf.fy.uav.common.response.order.ProductTypeResp;
import com.sf.fy.uav.common.response.order.SysPricingResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.order.controller.FeedbackRest;
import com.sf.fy.uav.order.controller.PricingRest;
import com.sf.fy.uav.order.controller.PricingRuleRest;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author LTQ
 */
@RestController
@RequestMapping("/home/pricing/")
@Api(tags = "定价管理")
public class SysPricingController {

    @Autowired
    private PricingRest pricingRest;

    @Autowired
    private FeedbackRest feedbackRest;

    @Autowired
    private PricingRuleRest pricingRuleRest;


    @GetMapping("get-pricing")
    @CrossOrigin
    public Rs<List<SysPricingResponse>> getPricing(@RequestParam Integer page, @RequestParam Integer size, /*@RequestParam(required = false) String landingCode,
                                                   @RequestParam(required = false) String takeoffCode*/
                                                   @RequestParam(required = false) Byte productType) {
        SysPricingRequest sysPricingRequest = new SysPricingRequest();
        sysPricingRequest.setPage(page);
        sysPricingRequest.setSize(size);
//        sysPricingRequest.setLandingCode(landingCode);
//        sysPricingRequest.setTakeoffCode(takeoffCode);
        sysPricingRequest.setProductType(productType);
        return Rs.success(pricingRest.getPricing(sysPricingRequest));
    }

    @GetMapping("get-total")
    @CrossOrigin
    public Rs<Long> getTotal(/*@RequestParam(required = false) String landingCode,
                             @RequestParam(required = false) String takeoffCode*/
            @RequestParam(required = false) Byte productType) {
        SysPricingRequest sysPricingRequest = new SysPricingRequest();
//        sysPricingRequest.setLandingCode(landingCode);
//        sysPricingRequest.setTakeoffCode(takeoffCode);
        sysPricingRequest.setProductType(productType);
        return Rs.success(pricingRest.getTotal(sysPricingRequest));
    }

    @PostMapping("/add")
    public Rs<Void> add(@RequestBody PricingAddRequest pricingAddRequest) {
        pricingRest.add(pricingAddRequest);
        return Rs.success();
    }

    @PostMapping("/edit")
    public Rs<Void> edit(@RequestBody PricingEditRequest pricingEditRequest) {
        pricingRest.edit(pricingEditRequest);
        return Rs.success();
    }

    @PostMapping("/disable")
    public Rs<Void> disablePricing(@RequestBody IdRequest idRequest) {
        pricingRest.disablePricing(idRequest);
        return Rs.success();
    }

    @GetMapping("/get-product-type")
    public Rs<List<ProductTypeResp>> getProductType() {
        return Rs.success(pricingRest.getProductType());
    }
}
